<template>
<!--测评2-->
  <div>
    <ceping>
      <p class="title" style="position: relative; padding-left: 120px">  <Button @click.stop="goAbilty" size="large" class="pull-left" style="position: absolute;left: 120px" shape="circle">我的能力</Button> 您可以通过以下6个维度进行测评</p>
      <chart :val="leidaValue"></chart>
      <ul class="ceping_lists clearfix">
        <li v-for="ability in abilityList" @click.stop="abilityCeping(ability.abilityitemId)">
          <div class="pull-left" >
            <p  v-if="ability.abilityitemCode === 'synthesis'">{{ability.abilityitem}}测评</p>
            <p  v-else>{{ability.abilityitem}}能力</p>
            <p>去测评 <Icon type="ios-arrow-forward" size="20"/></p>
          </div>
          <div  class="pull-right txt-center">
            <img :src="ability.duanIcon" alt="" width="70"  /><br>{{ability.gradeName}}
          </div>
        </li>
      </ul>
      <Spin fix v-show="isSpinShow" >
        <div class="loader">
          <Icon type="ios-loading" size=26 class="demo-spin-icon-load"></Icon>
          <div class="font14">加载中...</div>
        </div>
      </Spin>
    </ceping>
  </div>
</template>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  /* 旋转效果 */

  .demo-spin-icon-load{
    animation: ani-demo-spin 1s linear infinite;
  }
  @keyframes ani-demo-spin {
    from { transform: rotate(0deg);}
    50% { transform: rotate(180deg);}
    to { transform: rotate(360deg);}
  }
  /* 假如内容过长，一屏放不下，滚动条下拉覆盖不全 */
  .ivu-spin-fix {
    position: fixed;
  }


  .banner{
    height: 360px;
  }
  .divider{
    height: 53px;
    background-color: #fff;
    font-size: 14px;
    color: #957960;
    line-height: 53px;
    text-align: left;
    margin-bottom: 30px;
    box-shadow: 5px 1px 10px #ccc;
    a{
      color: #957960;
      &:hover{
        color: #9C7649;
        font-weight: 700;
      }
    }
    span{
      margin: 0 10px;
    }
  }

  .title{
    font-size: 31px;
    color: #000;
    text-align: center;
  }
  .ceping_lists{
    padding: 0 123px;
    margin-top: 30px;
    li{
      border:1px solid #eee;
      border-top:8px solid #957960;
      border-radius: 5px;
      padding: 20px 25px;
      float: left;
      margin-right: 40px;
      margin-bottom: 30px;
      box-shadow: 0 2px 10px rgba(0,0,0,0.1);
      height: 140px;
      width: 291px;
      cursor: pointer;
      .pull-left{
        width: 120px;
        padding-top: 15px;
        p:first-child{
          font-size: 18px;
          color: #000;
          margin-bottom: 5px;
        }
        p:last-child{
          font-size: 14px ;
          color: #999;
          i{
            margin-left: 5px;
            margin-bottom: 2px;
          }
        }
      }
    }
    li:nth-child(3n){
      margin-right: 0;
    }
  }

</style>
<script type="text/ecmascript-6">
  import ceping from '../template/ceping'
  import chart from '../template/chart'
  import {radarPage2,getSubject,centreInfoWeb,abilityPage} from '../../http'
  import {getStore} from '../../storage'
  import imgPathFilter from '../../myFilters'
    export default {
        name: 'ceping4',
        props: {},
        data() {
            return {
              abilityList:'',   //能力级别
              leidaValue:[],     //雷达图数据
              isSpinShow:false
            };
        },
        methods: {
          //跳转我的能力页面
          goAbilty(){
            this.$router.push({
              name:'ablity'
            })
          },
          //测评
          abilityCeping(abilityitemId){
            if(this.isSpinShow === false) {
              this.isSpinShow = true;
              //用户是否登录
              centreInfoWeb().then(res => {
                if (res.code === 200) {
                  //获取题目
                  getSubject({abilityitemId: abilityitemId}).then(res => {
                    //题库有相应题
                    if (res.data.list.length > 0) {
                      abilityPage().then(res => {
                        if (res.code === 200) {
                          console.info('isBuy：' + res.data.isBuy);
                          if (res.data.isBuy === 1) {
                            this.isSpinShow = false;
                            this.$router.push({
                              name: 'question',
                              query: {
                                abilityitemId: abilityitemId
                              }
                            })
                          } else {
                            this.isSpinShow = false;
                            this.$Notice.warning({
                              title: "人才测评提醒",
                              desc: "请先购买人才能力测评",
                              duration: 3,
                            });
                            this.$router.push({
                              name: 'ceping'
                            })
                          }
                        }else {
                          this.isSpinShow = false;
                          this.$Notice.warning({
                            title: "人才测评提醒",
                            desc: res.info,
                            duration: 3,
                          });
                        }
                      }).catch()
                    } else {        //题库暂无题目
                      this.isSpinShow = false;
                      this.$Notice.warning({
                        title: "人才测评提醒",
                        desc: "题库无相应题目，请进行其他测试",
                        duration: 3,
                      });
                    }
                  }).catch();
                } else {
                  this.isSpinShow = false;
                  this.$Notice.warning({
                    title: '登录提醒 ',
                    desc: '使用人才测评，需用户登录！ ',
                    duration: 3,
                  });
                  this.$router.push({name: 'ceping'});
                }
              })
            }
          },
          //雷达图分值
          getLeidaScore(list){
            let scores=new Array() ;
            let sa='';
            for(sa in list){
              scores.push(list[sa].rait);
            }
            return scores;
          },
          duan(Name){
              return Name.substring(Name.length-2);
          },
          //雷达图数据整理
          getRaddar(arr){
            var newarr = new Array();
            var serarr = ["serve","manage","marketing","develop","maintain","finance","synthesis"];
            for(let i = 0;i < serarr.length; i++){
              for(let j = 0;j < arr.length; j++){
                if(serarr[i] === arr[j].abilityitemCode){
                  newarr.push(arr[j]);
                  break;
                }
              }
            }
            return newarr;
          },
          //能力数据整理
          getAbilities(arr){
            var newarr = new Array();
            var serarr = ["serve","finance","maintain","develop","marketing","manage","synthesis"];
            for(let i = 0;i < serarr.length; i++){
              for(let j = 0;j < arr.length; j++){
                if(serarr[i] === arr[j].abilityitemCode){
                  newarr.push(arr[j]);
                  break;
                }
              }
            }
            return newarr;
          },
          getCeping4(){
            if(this.isSpinShow === false) {
              this.isSpinShow = true;
              //用户是否登录
              centreInfoWeb().then(res => {
                if (res.code === 200) {
                  //是否购买人才测评
                  abilityPage().then(res => {
                    if (res.code === 200) {
                      if (res.data.isBuy === 1) {
                        //雷达图数据
                        radarPage2().then(res => {
                          this.isSpinShow = false;
                          if(res.code === 200) {
                            this.abilityList = this.getAbilities(res.data.abilityList);
                            this.leidaValue = this.getLeidaScore(this.getRaddar(res.data.abilityList))
                          }else {
                            this.$Notice.warning({
                              title: "人才测评提醒",
                              desc: res.info,
                              duration: 3,
                            });
                          }
                        }).catch()
                      } else {
                        this.isSpinShow = false;
                        this.$Notice.warning({
                          title: "人才测评提醒",
                          desc: "请先购买人才能力测评",
                          duration: 3,
                        });
                        this.$router.push({
                          name: 'ceping'
                        })
                      }
                    }else {
                      this.isSpinShow = false;
                      this.$Notice.warning({
                        title: "人才测评提醒",
                        desc: res.info,
                        duration: 3,
                      });
                    }
                  }).catch()
                } else {
                  this.isSpinShow = false;
                  this.$Notice.warning({
                    title: '登录提醒 ',
                    desc: '使用人才测评，需用户登录！ ',
                    duration: 3,
                  });
                  this.$router.push({name: 'ceping'});
                }
              }).catch()
            }
          }
        },
        created() {
          this.getCeping4()
          /*this.$router.push({
            name:'ceping'
          })*/
        },
        components: {
          ceping,
          chart
        }
    }
</script>
